package com.hyt.it.ogt.pj.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hyt.core.base.BaseServiceImpl;
import com.hyt.it.ogt.pj.common.ResponseCode;
import com.hyt.it.ogt.pj.mapper.UserConfigMapper;
import com.hyt.it.ogt.pj.model.entity.UserConfig;
import com.hyt.it.ogt.pj.service.IUserConfigService;

/**
 * <p>
 * 用户配置表表 服务实现类
 * </p>
 *
 * @author qiaozj
 * @since 2020-07-09
 */
@Service
public class UserConfigServiceImpl extends BaseServiceImpl<UserConfigMapper, UserConfig> implements IUserConfigService {

    @Autowired
    private UserConfigMapper userConfigMapper;

    /**
     * 获取当前评卷项目id
     * @param userId 用户id
     * @param key 参数key
     * @return 返回配置信息
     */
    @Override
    public UserConfig getSelectProject(String userId, String key) {
        UserConfig userConfig = userConfigMapper.getSelectProject(userId, key);
        return userConfig;
    }

    /**
     * 设置用户配置
     * @param userId 用户id
     * @param key 参数key
     * @param value 参数值
     * @return 返回设置状态码
     */
    @Override
    public Integer setUserConfig(String userId, String key, String value) {
        UserConfig userConfig = getSelectProject(userId, key);
        if(userConfig != null){
            Integer code = userConfigMapper.setUserConfig(userId, key, value);
        }else{
            userConfig = new UserConfig();
            userConfig.setUserId(userId);
            userConfig.setLabel(key);
            userConfig.setValue(value);
            save(userConfig);
        }
        return ResponseCode.SUCCESS;
    }
}
